package com.tdkj.action.backstage.shop;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.tdkj.action.BaseAction;
import com.tdkj.model.shop.BeanMallNotice;
import com.tdkj.service.shop.IBeanMallNoticeService;


public class MallNoticeAction extends BaseAction {
    
	private IBeanMallNoticeService mallNoticeService;
	
	
	private BeanMallNotice mallNotice ;
	private List<BeanMallNotice> mallNotices ;
	
	public String add() {
		mallNotice.setUser(this.getCurrentUser());
		mallNotice.setPublishTime(new Date(System.currentTimeMillis()));
		mallNoticeService.save(mallNotice);
		return execute();
	}
	
	public String update() {
		mallNoticeService.saveOrUpdate(mallNotice, BeanMallNotice.class);
		return edit();
	}

	public String del() {
		mallNoticeService.delete(mallNotice.getId(), BeanMallNotice.class);
		return execute();
	}
	
	public String edit() {
		mallNotice = mallNoticeService.findById(mallNotice.getId(), BeanMallNotice.class);
		return "edit";
	}
	
	public String execute() {
		Criteria criteria = this.createCriteria(BeanMallNotice.class)
		.addOrder(Order.desc("publishTime"));
		this.queryByPage(criteria, "orderManageAction.action", 10);
		
		return "success";
	}

	public BeanMallNotice getMallNotice() {
		return mallNotice;
	}

	public void setMallNotice(BeanMallNotice mallNotice) {
		this.mallNotice = mallNotice;
	}

	public List<BeanMallNotice> getMallNotices() {
		return mallNotices;
	}

	public void setMallNotices(List<BeanMallNotice> mallNotices) {
		this.mallNotices = mallNotices;
	}

	@Resource
	public void setMallNoticeService(IBeanMallNoticeService mallNoticeService) {
		this.mallNoticeService = mallNoticeService;
	}

}
